package com.changgou.page.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.feign.SpuFeign;
import com.changgou.goods.pojo.Spu;
import com.changgou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/page")
public class PageController {

    @Autowired
    private PageService pageService;
    @Autowired
    private SpuFeign spuFeign;

    /**
     * 将 所有 的 spu 进行 页面静态化资源的生成
     * 只是一个调用方法
     * @return
     */
    @RequestMapping("/generateAllItemPage")
    public Result generateAllItemPage(){
        List<Spu> spuList = spuFeign.findAll().getData();
        for (Spu spu : spuList) {
            pageService.generateItemPage(spu.getId());
        }
        return new Result(true, StatusCode.OK,"生成静态化页面成功！");
    }
}
